//
//  DnPhotoViewCell.m
//  DnPhotoGallery	
//
//  Created by Ngoc on 12/12/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "DnPhotoViewCell.h"

@interface DnPhotoViewCell (Private)
-(void) setUpWithDefaultValue;
@end

@implementation DnPhotoViewCell
@synthesize userData=_userData, isSelected =_isSelected;

-(id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUpWithDefaultValue];
    }
    return self;
}
-(id) init
{
    self = [super init];
    if (self) {
        
        [self setUpWithDefaultValue];
    }
    return self;
}
-(void) setUpWithDefaultValue
{
    _userData = [[NSMutableDictionary alloc]init];
}
-(void) dealloc
{
    [_userData release];
    [super dealloc];
}
-(void) setIsSelected:(BOOL)isSelected
{
    if (isSelected) {
        if (!coverView) {
           coverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
            coverView.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.5f ];
            if (!selectedIcon) {
                selectedIcon = [UIImage imageNamed:@"ok-icon.png"];
            }
            UIImageView *imageView = [[UIImageView alloc]initWithImage:selectedIcon];
            imageView.frame = CGRectMake(coverView.frame.size.width/2-selectedIcon.size.width/2, coverView.frame.size.height-selectedIcon.size.height, selectedIcon.size.width, selectedIcon.size.height);
            [coverView addSubview:imageView];
            [imageView release];
        }
        [self addSubview:coverView];
        [self bringSubviewToFront:coverView];
    }
    else
    {
        if (coverView) {
            [coverView removeFromSuperview];
        }
    }
    _isSelected = isSelected;
    [self setNeedsDisplay];
}
@end

